import Util from '@/utils/Util';
import Constant from '@/constant/Constants';
import LoggerUtil from '@/utils/LoggerUtil';

export default class GoodsInfo {
    GOODS_UNITS:Array<string> = ["箱","个","份","袋","盒","瓶"];
    id: number;
    name:string=null;
    image:string='';
    stock:number =0 ;
    media:string ='';
    desc:string=null;
    currPrice:number=null;
    origPrice:number=null;
    costPrice:number=null;
    merPrice:number=null;
    spec:string=null;
    from:string=null;
    channelId:number=null;
    unit:string=null;
    categoryId:number;
    price: number;
    count: number = 0;
    select: boolean = true;
    commissionRate:number=0;
    goodsImageList = new Array<string>();
    goodsImgLimit: number = 4;
    goodsInfoMediaList = new Array<string>();
    goodsInfoMediaLimit: number = 4;
    selectUnitIndex:number = -1;
    selectCategoryIndex: number = -1;
    selectChannelIndex:number = -1;
    link:string='';
    GoodsInfo(){}
    changeSelect():void {
        this.select = this.select ? false : true;
    }

    getTotalMoney(){
        return this.count*this.merPrice;
    }

    setMedia(){
        if (!Util.isEmpty(this.goodsImageList)){
            this.image = this.goodsImageList.join(",").replace(Constant.cdnHost,"");
        }else{
            this.image = null;
        }

        if (!Util.isEmpty(this.goodsInfoMediaList)){
            this.media = this.goodsInfoMediaList.join(",").replace(Constant.cdnHost,"");
        }else{
            this.media =null;
        }

    }

    public setImageList(){
        if(Util.isEmpty(this.media)){
            return ;
        }
        this.goodsImageList.length = 0 ;
        this.media.split(",").filter(item=>item.indexOf(".mp4")<0).forEach(item=>this.goodsImageList.push(item));
    }


    _clear(){
        Util.copyWithNull(this,new GoodsInfo())
    }
    
}

